<?php

namespace App\Console\Commands\Common;

use App\Models\Common\CityTerritorialBoundaryModel;
use App\Models\Common\ResourcesModel;
use App\Remote\AMap\AMapRemote;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class ClearResources extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'common:clear-resources';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '定期清理resources表软删除数据';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $delCount = ResourcesModel::withoutGlobalScope('isDel')->where('createdAt', '<', time() - 90 * 86400)->where('isDeleted', 1)->delete();
        $this->info("del count: {$delCount}");

        Log::info("clear-resources count: {$delCount}");
    }
}
